package com.itheima.controller.backend.security;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.OrderSetting;
import com.itheima.pojo.dto.OrderSettingDTO;
import com.itheima.pojo.vo.OrderSettingVO;
import com.itheima.service.OrderSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.PerformanceSensitive;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Date;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/ordersetting")
@Api(tags = "预约设置管理")
public class OrderSettingController {


	@Autowired
	private OrderSettingService orderSettingService;

	@GetMapping("/download")
	@ApiOperation("模板下载")
	public String download(HttpServletResponse response, String filename) {
		orderSettingService.download(response, filename);
		return "文件下载";
	}

	@PostMapping("/editNumberByOrderDate")
	@ApiOperation("根据日期修改可预约人数")
	public Result editNumberByOrderDate(@RequestBody OrderSettingDTO orderSettingDTO) {
		Integer recordCount = orderSettingService.editNumberByOrderDate(orderSettingDTO);

		return new Result(true, MessageConstant.ORDERSETTING_FAIL, recordCount);
	}

	@GetMapping("/getOrderSettingByMonth")
	@ApiOperation("根据年月查询预约设置")
	public Result getOrderSettingByMonth(String month) {
		List<OrderSettingVO> list = orderSettingService.getOrderSettingByMonth(month);
		return new Result(true, MessageConstant.GET_ORDERSETTING_SUCCESS, list);
	}

	@PostMapping("/upload")
	@ApiOperation("上传excel文件")
	public Result upload(MultipartFile file) throws IOException {
		Integer recordCount = orderSettingService.upload(file);
		return new Result(true, "上传成功", recordCount);
	}
}

